package org.zhadoop.stream.cql.semanticanalyzer.analyzecontext.expressiondesc;

import java.util.List;

import org.zhadoop.stream.api.opereators.JoinType;

import com.google.common.collect.Lists;

/**
 * Join表达式描述
 * @author zwd
 *
 */
public class JoinExpressionDesc implements ExpressionDescribe{
	private JoinType jointype;
	
	private ExpressionDescribe leftExpression;
	
	private ExpressionDescribe rightExxpression;
	
	private ExpressionDescribe joinCondition;
	
	public JoinExpressionDesc(JoinType type) {
		this.jointype = type;
	}
	
	@Override
	public String toString() {
		return jointype.toString();
	}
	
	/**
	 * 按照从左到右的顺序，获取所有的join的流名称
	 * @return
	 */
	public List<StreamAliasDesc> getOrderedStreams(){
		List<StreamAliasDesc> list =  Lists.newArrayList();
		if(leftExpression instanceof JoinExpressionDesc){
			list.addAll(((JoinExpressionDesc) leftExpression).getOrderedStreams());
		}else{
			list.add((StreamAliasDesc)leftExpression);
		}
		
		if(rightExxpression instanceof JoinExpressionDesc){
			list.addAll(((JoinExpressionDesc) rightExxpression).getOrderedStreams());
		}else{
			list.add((StreamAliasDesc)rightExxpression);
		}
		return list;
	}

	public JoinType getJointype() {
		return jointype;
	}

	public void setJointype(JoinType jointype) {
		this.jointype = jointype;
	}

	public ExpressionDescribe getLeftExpression() {
		return leftExpression;
	}

	public void setLeftExpression(ExpressionDescribe leftExpression) {
		this.leftExpression = leftExpression;
	}

	public ExpressionDescribe getRightExxpression() {
		return rightExxpression;
	}

	public void setRightExxpression(ExpressionDescribe rightExxpression) {
		this.rightExxpression = rightExxpression;
	}

	public ExpressionDescribe getJoinCondition() {
		return joinCondition;
	}

	public void setJoinCondition(ExpressionDescribe joinCondition) {
		this.joinCondition = joinCondition;
	}	
}
